<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body>
<div id="div">
    <el-container>
        <el-header>
            <div class="content-header">
                <h1>系统设置
                    <small>权限管理</small>
                </h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>系统设置</el-breadcrumb-item>
                    <el-breadcrumb-item>角色管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
        </el-header>
        <el-container>
            <el-container>
                <div class="filter-container">
                    &nbsp; &nbsp; &nbsp;
                    <el-input placeholder="角色名" v-model="pagination.queryString" style="width: 200px;"
                              class="filter-item"></el-input>
                    <el-button @click="findByPage()" class="dalfBut">查询</el-button>
                </div>
                <el-main>
                    <el-table :data="tableData" style="width: 100%">
                        <el-table-column prop="name" label="角色名" width="180" align="center"></el-table-column>
                        <el-table-column prop="keyword" label="角色代号" align="center"></el-table-column>
                        <el-table-column label="角色描述" align="center" prop="description">
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">权限管理</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <div class="add-form">
                        <el-dialog title="编辑菜单" :visible.sync="dialogFormVisible4Edit">
                            <el-form label-position="right" label-width="100px">
                                <table >
                                    <thead>
                                    <tr>
                                        <th> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  菜单名称</th>
                                        <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  选择</th>
                                    </tr>
                                    </thead>
                                    <tr v-for="(c,index) in roleData">
                                        <td><label :for="c.id">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;{{c.name}}</label></td>
                                        <td >
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                        </td>
                                    </tr>
                                </table>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </el-main>
                <el-footer>
                </el-footer>
            </el-container>
        </el-container>
    </el-container>

</div>

<script>
    new Vue({
        el:"#div",
        data:{
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dialogFormVisible4Edit:false,

            tableData:[],
            roleData:[],
            checkitemIds:[],
            username:''

        },
        methods:{

            //分页查询
            findByPage() {
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/role/findPage.do", param)
                    .then(data => {
                        this.tableData = data.data.rows;
                        this.pagination.total = data.data.total
                    })

            },

            handleUpdate(row){
                this.dialogFormVisible4Edit = true;
                axios.get("/role/findAllMenu.do").then(data=>{
                    if(data.data.flag){
                        this.roleData = data.data.data;
                    }else {
                        this.$message.error(data.data.message)
                    }

                });



                axios.post("/role/findCheckitemIdsByUsername.do?username="+row.name)
                    .then(data=>{
                    if(data.data.flag){
                        this.checkitemIds = data.data.data;
                        this.username=row.name
                    }else {
                        this.$message.error(data.data.message)
                    }
                })

            },


            handleEdit(){
                axios.post("/role/editRoleMenu.do?username="+this.username,this.checkitemIds,)
                    .then(data=>{
                        if(data.data.flag){
                            this.dialogFormVisible4Edit=false;
                            this.$message.success(data.data.message)
                        }else {
                            this.$message.error(data.data.message)
                        }
                    })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findByPage();
            },
        },
        created(){
            this.findByPage();
        }


    })
</script>
</body>
</html>